﻿using Furion.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using Furion.DataEncryption;

namespace PMP.Web.Core;

public class JwtHandler : AppAuthorizeHandler
{
    public override async Task HandleAsync(AuthorizationHandlerContext context, DefaultHttpContext httpContext)  
    {  
        // 自动刷新 token  
        if (JWTEncryption.AutoRefreshToken(context, httpContext))  
        {  
            await AuthorizeHandleAsync(context);  
        }  
        else  
        {  
            context.Fail();  
        }  
    }  
  
    public override async Task<bool> PipelineAsync(AuthorizationHandlerContext context, DefaultHttpContext httpContext)  
    {  
        // 这里可以添加自定义授权逻辑  
        return await Task.FromResult(true);  
    }  
}